Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure posix path sep is used #728

Merged
merged 3 commits into from
Oct 2, 2023
Merged

fix: ensure posix path sep is used #728

merged 3 commits into from
Oct 2, 2023

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Oct 2, 2023

Description of changes

Alternative to #727

See https://github.com/aws-amplify/amplify-cli/issues/13289 for details. path.relative behaves differently on windows. https://nodejs.org/api/path.html#pathrelativefrom-to

This results in the generated path being invalid syntax in TypeScript/JavaScript.

This change replaces the windows path separator (path.win32.sep) with the posix path separator (path.posix.sep).

Issue #, if available

https://github.com/aws-amplify/amplify-cli/issues/13289

Description of how you validated changes

  • Unit tests
  • Need to test on window machine

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dpilch dpilch requested a review from a team as a code owner October 2, 2023 16:59
svidgen
svidgen previously approved these changes Oct 2, 2023
Comment on lines +5 to +9
const relativePath = path
.relative(opsGenDirectory, generatedFileName)
// ensure posix path separators are used
.split(path.win32.sep)
.join(path.posix.sep);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is OK. But, is there any possibility that this affects any other downstream consumers of the relativePath in unintended (negative) ways?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All path and fs functions accept posix style paths even on a windows machine. So I think it should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e.

> path.resolve('./packages/graphql-generator/package.json')
D:\\Users\\dppilche\\amplify-codegen\\packages\\graphql-generator\\package.json

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more so wondering if we do any path splitting or merging that could break due to it looking for os delimiting.

@alharris-at alharris-at merged commit 9c9e1ba into main Oct 2, 2023
4 checks passed
@alharris-at alharris-at deleted the win-relative branch October 2, 2023 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants